package cn.burnit.view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 管理员主界面
 */
public class RootMainForm extends JFrame {
    private JMenu maintain,borrowManage,checkManage,sysManage,bookInfoMaintain;
    private JMenuBar menuBar;
    private JMenuItem readerInfoMainatin,borrowBook,reurnBook,bookInfoCheck,bookInfoAllCheck,readerInfoCheck
            ,addBook,updateBook,delBook
            ,exitSys,checkAllReader;
    private JLabel label;


    public RootMainForm(){

        Container container = getContentPane();
        container.setLayout(null);
        label=new JLabel("欢迎进入图书管理系统");
        label.setFont(new Font("宋体", Font.PLAIN, 24));
        label.setBounds(180,100,300,100);
        label.setLayout(new FlowLayout(FlowLayout.CENTER));
        menuBar=new JMenuBar();
        maintain=new JMenu("基础维护");
        borrowManage=new JMenu("借阅管理");
        checkManage=new JMenu("查询管理");
        sysManage=new JMenu("系统管理");
        bookInfoMaintain=new JMenu("图书信息维护");
        readerInfoMainatin=new JMenu("读者信息维护");


        borrowBook=new JMenuItem("借书");
        reurnBook=new JMenuItem("还书");
        bookInfoCheck=new JMenuItem("图书信息查询");
        bookInfoAllCheck=new JMenuItem("查看全部图书");
        readerInfoCheck=new JMenuItem("读者信息查询");
        addBook=new JMenuItem("添加图书");
        updateBook=new JMenuItem("修改图书");
        delBook=new JMenuItem("删除图书");
        exitSys=new JMenuItem("退出系统");
        checkAllReader=new JMenuItem("查看所有读者");
        //退出系统
        exitSys.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showConfirmDialog(null,"真的要退出系统吗？");
                new LoginForm();
                dispose();
            }
        });
        //跳转到查看所有图书界面
        bookInfoAllCheck.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new CheckAllBookForm();
            }
        });
        //跳转到查看指定条件图书信息界面（模糊查询）
        bookInfoCheck.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new CheckBookForm();
            }
        });
        //跳转到借书界面
        borrowBook.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new BorrowBookForm();
            }
        });
        //跳转到还书界面
        reurnBook.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ReturnBookForm();
            }
        });
        //跳转到添加图书界面
        addBook.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AddBookForm();
            }
        });
        //跳转到更新图书界面
        updateBook.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new UpdateBookForm();
            }
        });
        //跳转到删除图书界面
        delBook.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new DeleteBookForm();
            }
        });
        //跳转到查看所有读者界面
        checkAllReader.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new CheckAllReaderForm();
            }
        });

        menuBar.add(maintain);
        menuBar.add(borrowManage);
        menuBar.add(checkManage);
        menuBar.add(sysManage);

        maintain.add(bookInfoMaintain);//添加图书信息维护
        maintain.add(readerInfoMainatin);//添加读者信息维护
        borrowManage.add(borrowBook);//添加借书
        borrowManage.add(reurnBook);//添加还书
        checkManage.add(bookInfoAllCheck);//添加查看所有图书
        checkManage.add(bookInfoCheck);//添加条件查询图书
        //checkManage.add(readerInfoCheck);//添加读者信息查询
        //图书信息维护
        bookInfoMaintain.add(addBook);//添加图书
        bookInfoMaintain.add(updateBook);//更新图书
        bookInfoMaintain.add(delBook);//删除图书
        //读者信息维护
        readerInfoMainatin.add(checkAllReader);//添加查看所有读者
        sysManage.add(exitSys);

        setJMenuBar(menuBar);
        container.add(label);

        setTitle("图书管理系统");
        setSize(600,400);
        setLocationRelativeTo(null);
        setResizable(false);
        setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

//    public static void main(String[] args) {
//        new RootMainForm();
//    }
}
